﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
 <div class="layuimini-container">
     <div class="layuimini-main">
         <fieldset class="table-search-fieldset">
             <div style="margin: 10px 10px 10px 10px">
                 <form class="layui-form layui-form-pane" >
                     <div class="layui-form-item">
                         <div class="layui-inline">
                             <label class="layui-form-label">关键字:</label>
                             <div class="layui-input-inline">
                                 <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" >
                             </div>
                         </div>
                        <div class="layui-inline"> 
                             <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                         </div>
                     </div>
                 </form>
             </div>
         </fieldset>
         <script type="text/html" id="toolbarDemo">
             <div class="layui-btn-container" id="toolbar">
                 <button id="NF-add" authorize class="layui-btn  data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                 <button id="NF-delete" authorize class="layui-btn  layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                 <button id="NF-details" authorize class="layui-btn  layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                 <button id="NF-views" authorize class="layui-btn layui-btn-warm" lay-event="views"> <i class="layui-icon">&#xe60b;</i>预览模式</button>
             </div>
         </script>
         <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
     </div>
 </div>
 <script>
     layui.use(['jquery', 'form', 'table', 'common', 'tablePlug', 'treeTable','layer'], function () {
         var $ = layui.jquery,
             form = layui.form,
             layer = layui.layer,
             table = layui.table,
             treeTable = layui.treeTable,
             common = layui.common;
         var entity;
         var loading = layer.load(0, { shade: false });
         //权限控制(js是值传递)
         toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
         common.rendertable({
             elem: '#currentTableId',
             url: '/BasicData/Policies/GetGridJson',
             sqlkey: 'F_Id',//数据库主键
             cols: [[
                 { field: 'F_Id', title: 'ID', sort: true, hide: true, hideAlways: true },
                 //此处需修改
                 { field: 'F_Title', title: '标题', width: 600, sort: true },
                 { field: 'F_CreateTime', title: '发表时间', width: 200, sort: true, 
                     templet: "<div>{{layui.util.toDateString(d.F_CreateTime, 'yyyy-MM-dd')}}</div>"
                 },
                 {
                     field: 'F_Content', title: '下载链接', minWidth: 200, 
                     templet: function (d) {
                         return "<a  onclick=\"downloaddata('" + d.F_Content+"')\">点击下载</a>"
                     }},
             ]]
         });
         // 监听搜索操作
         form.on('submit(data-search-btn)', function (data) {
             //执行搜索重载
             common.reloadtable({
                 elem: 'currentTableId',
                 curr: 1,
                 where: { keyword: data.field.txt_keyword}
             });
             return false;
         });
         table.on('row(currentTableFilter)', function (obj) {
             obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
             entity = obj;
         })
         //toolbar监听事件
         table.on('toolbar(currentTableFilter)', function (obj) { 
             if (obj.event === 'add') {  // 监听添加操作
                 common.modalOpen({
                     title: "添加界面",
                     url: "/BasicData/Policies/Form",
                     width: "500px",
                     height: "500px",
                 });
             }
             else if (obj.event === 'delete') {
                 if (entity == null) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.deleteForm({
                     url: "/BasicData/Policies/DeleteForm",
                     param: { keyValue: entity.data.F_Id },
                     success: function () {
                         common.reload('data-search-btn');
                         entity = null;
                     }
                 });
             }
             else if (obj.event === 'edit') {
                 if (entity == null) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.modalOpen({
                     title: "编辑界面",
                     url: "/BasicData/Policies/Form?keyValue=" + entity.data.F_Id,
                     width: "500px",
                     height: "500px",
                 });
             }
             else if (obj.event === 'details') {
                 if (entity == null) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.modalOpen({
                     title: "查看界面",
                     url: "/BasicData/Policies/Details?keyValue=" + entity.data.F_Id,
                     width: "500px",
                     height: "500px",
                     btn: []
                 });
             }

             else if (obj.event === 'views') {
                 layer.open({
                     type: 1
                     , title: false//不显示标题栏
                     , closeBtn: false
                     , area: '300px;'
                     , shade: 0.8
                     , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                     , btn: ['朕知道了']
                     , btnAlign: 'c'
                     , moveType: 1 //拖拽模式，0或者1
                     , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">预览模式<br>仅支持pdf文件和普通图片在线预览<br>此功能正在开发中哦<br>请耐心等待 ^_^</div>'
                     , success: function (layero) {
                         var btn = layero.find('.layui-layer-btn1');
                         btn.find('.layui-layer-btn').attr({
                             href: '/'
                             , target: '_blank'
                         });
                     }
                 });
             }
           return false;
       });
     });

     function downloaddata(content) {
         window.location.href = "http://"+content+"";
     }
</script>
